#region Copyright and Licensing Notice
// Copyright (C) 2011 Steven Bosnick
// 
// This program is open source software; you can redistribute it 
// and/or modifiy it under the terms of the Eclipse Public License,
// version 1.0.
// 
// This program is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A 
// PARTICULAR PURPOSE. See the Eclipse Public License for more
// details.
// 
// You should have received a copy of the Eclipse Public License 
// along with this program; if not, you can find a copy at
// "http://www.opensource.org/licenses/eclipse-1.0.php".
#endregion
using System.Collections.ObjectModel;
using System.Linq;
using BitwiseOre.SharedMemory.Core.Primatives;
using NUnit.Framework;

namespace BitwiseOre.Tests.SharedMemory.Primatives
{
    [TestFixture]
    public sealed class EnumerableExtensionsFixture : AssertionHelper
    {
        [Test(Description = "The initial item from a ring buffer is the initial item of the underlying collection.")]
        public void ToRingBuffer_InitialItem()
        {
            var collection = new ReadOnlyCollection<int>(new[] {34, 35, 36, 37});

            var ring = collection.ToRingBuffer();
            var result = ring.First();

            Expect(result, EqualTo(collection[0]));
        }

        [Test(Description = "The ring buffer wraps around to provide the initial item again after all items " +
                            "in the collection have been provided once.")]
        public void ToRingBuffer_WrapsAroundCollection()
        {
            var collection = new ReadOnlyCollection<int>(new[] {34, 35, 36, 37});

            var ring = collection.ToRingBuffer();
            var result = ring.Take(collection.Count + 1).Last();

            Expect(result, EqualTo(collection[0]));
        }

    }
}